﻿app.controller('PwdCtrl', [
        '$scope', '$http', '$state', 'alertService',
        function($scope, $http, $state, alertService) {
            $scope.verify = function() {
                $http.post('/api/account/forgotpwd?userName=' + $scope.phone + '&email=' + $scope.email)
                    .success(function(result) {
                        if (result.Code >= 0) {
                            $scope.isCollapsed = false;
                        } else {
                            alertService.add(result.Message);
                        }
                    }).error(function(x) {
                        alertService.error('发送验证码异常', x);
                    });
            };

            $scope.setPwd = function() {
                if ($scope.pwd !== $scope.pwd2) {
                    alertService.add('两次输入的密码不相同');
                    return;
                }
                $http.post('/api/account/SetPassword', {
                    Phone: $scope.phone,
                    Email: $scope.email,
                    NewPassword: $scope.pwd,
                    ConfirmPassword: $scope.pwd2,
                    Code: $scope.code
                }).success(function(result) {
                    if (result.Code >= 0) {
                        alertService.add('修改成功，2秒后返回登录页面','success',2);
                        setTimeout(function() {
                            $state.go('access.signin');
                        }, 2000);
                    } else {
                        alertService.add(result.Message);
                    }
                }).error(function(x) {
                    alertService.error('发送验证码异常', x);
                });
            };
        }
    ]);